/********************************** (C) COPYRIGHT *******************************
 * File Name          : CH392CMD.H
 * Author             : WCH
 * Version            : V1.0
 * Date               : 2022/12/28
 * Description        : CH392 command interface file
 *******************************************************************************/
#ifndef __CH392CMD_H__
#define __CH392CMD_H__
#include "debug.h"

#if (CH392_OP_INTERFACE_MODE == 1) /* SEL = 1 */

#define xWriteCH392Cmd(cmd) UARTWriteCH392Cmd(cmd)
#define xWriteCH392Data(mdata) UARTWriteCH392Data(mdata)
#define xReadCH392Data() UARTReadCH392Data()
#define xCH392CmdStart()
#define xEndCH392Cmd()

#elif (CH392_OP_INTERFACE_MODE == 2) /* SEL = 0 */

#define xWriteCH392Cmd(cmd) SPIWriteCH392Cmd(cmd)
#define xWriteCH392Data(mdata) SPIWriteCH392Data(mdata)
#define xReadCH392Data() SPIReadCH392Data()

#define xCH392CmdStart() SPICH392CmdStart()
#define xEndCH392Cmd() SPIEndCH392Cmd()
#endif

void CH392Reset(void); /* hardware Reset */

void CH392CMDReset(void); /* Reset */

UINT8 CH392CMDGetVer(void); /* Obtain the chip and firmware version number */

UINT8 CH392CMDCheckExist(UINT8 testdata); /* Test communication interface and working condition` */

UINT8 CH392CMDGetPHYStatus(void); /* Gets the current PHY status */

UINT8 CH392CMDInitCH392(void); /* Initialize CH392 */

void CH392CMDSetUartBaudRate(UINT32 baudrate); /* Set the baudrate for serial port communication */

UINT8 CH392CMDGetCmdStatus(void); /* Obtain the command execution status */

void CH392CMDSetIPAddr(UINT8 *ipaddr); /* Set IP address */

void CH392CMDSetGWIPAddr(UINT8 *gwipaddr); /* Set GWIP address */

void CH392CMDSetMASKAddr(UINT8 *maskaddr); /* Set MASK address */

void CH392CMDSetMACAddr(UINT8 *amcaddr); /* Set MAC address */

void CH392CMDGetMACAddr(UINT8 *amcaddr); /* Gets the MAC address */

void CH392CMDGetUnreachIPPT(UINT8 *list); /* Get unreachable information (IP,Port,Protocol Type) */

void CH392CMDGetRemoteIPP(UINT8 sockindex, UINT8 *list); /*Obtain the port and IP address of the remote end */

void CH392CMDSetSocketDesIP(UINT8 sockindex, UINT8 *ipaddr); /* Set the destination IP address of socket n  */

void CH392CMDSetSocketProtType(UINT8 sockindex, UINT8 prottype); /* Set the protocol type of socket n  */

void CH392CMDSetSocketDesPort(UINT8 sockindex, UINT16 desprot); /* Set the destination port of socket n */

void CH392CMDSetSocketSourPort(UINT8 sockindex, UINT16 surprot); /* Set the source port of socket n */

void CH392CMDSendData(UINT8 sockindex, UINT8 *databuf, UINT16 len); /* Writes data to socket n buffer */

UINT16 CH392CMDGetRecvLength(UINT8 sockindex); /* Gets the length of data received by socket n */

void CH392CMDClearRecvBuf(UINT8 sockindex); /* Clear receive buffer  */

void CH392CMDGetRecvData(UINT8 sockindex, UINT16 len, UINT8 *pbuf); /* Gets socket n receive buffer data */

UINT16 CH392CMDGetSocketStatus(UINT8 sockindex); /* Obtain the socket n status */

UINT8 CH392CMDOpenSocket(UINT8 sockindex); /* Open socket n */

UINT8 CH392CMDCloseSocket(UINT8 sockindex); /* Close socket n*/

UINT8 CH392CMDTCPConnect(UINT8 sockindex); /* TCP Connect */

UINT8 CH392CMDTCPListen(UINT8 sockindex); /* TCP Listen */

UINT8 CH392CMDTCPDisconnect(UINT8 sockindex); /* TCP Disconnect */

UINT8 CH392CMDGetSocketInt(UINT8 sockindex); /* Gets the interrupt status of socket n  */

void CH392CMDGetIPInf(UINT8 *addr); /* Get IP, subnet mask, gateway */

UINT8 CH392CMDDHCPEnable(UINT8 flag); /* Enable DHCP */

u8 CH392CMDGetDHCPStatus(void); /* Obtain DHCP status */

void CH392CMDSetSocketRecvBuf(UINT8 sockindex, UINT8 startblk, UINT8 blknum); /* Sets the SOCKET receive buffer */

UINT8 CH392CMDGetGlobIntStatus_392F(void); /* Gets the CH392F global interrupt status */

UINT16 CH392CMDGetGlobIntStatus_392T(void); /* Gets the CH392T global interrupt status */

void CH392CMDSetKeepLive(UINT8 sockindex, UINT8 cmd); /* Set the socket n keeplive function */

void CH392CMDKeepLiveCNT(UINT8 cnt); /* Set KEEPLIVE retries times */

void CH392CMDKeepLiveIDLE(UINT32 idle); /* Set KEEPLIVE idle time */

void CH392CMDKeepLiveINTVL(UINT32 intvl); /* Set KEEPLIVE interval time */

void CH392CMDSetTTLNum(UINT8 sockindex, UINT8 TTLnum); /* Set the TTL */

u8 CH392CMDGetIdleSendQueue(); /* Get 392 idle send queue */

u8 CH392SetUartBaudRate(UINT32 baudrate); /* Set 392 Uart BaudRate */

#endif
/**************************** endfile *************************************/
